#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e4 + 10;
int t, n;
ll k[N], h[N];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> k[i];
        for (int i = 1; i <= n; i++) cin >> h[i];

        ll ans = h[1] * (h[1] + 1) / 2, dmg = h[1];
        // cout << "---" << ans << endl;

        for (int i = 2; i <= n; i++) {
            ll B = dmg + (k[i] - k[i - 1]);
            ll C = k[i] - k[i - 1];
            if (h[i] > B) {
                ans = k[i] * (k[i] + 1) / 2;
                dmg = h[i];
            }
            else if (h[i] > C) {
                ans = B * (B + 1) / 2;
                dmg = B;
            }
            else {
                ans += h[i] * (h[i] + 1) / 2;
                dmg = h[i];
            }
            // cout << "---" << ans << endl;
        }
        cout << ans << endl;
    }
    return 0;
}